<#import "/manage/tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="广告管理">
<!--suppress ALL -->
<#----------------------------------------------查询表单begin----------------------------------------------->
<form id="searchForm" class="form-panel">
    <ul class="panel-content">
        <li>
            <div class="control-group span7">
                <label class="control-label">广告标题:</label>
                <div class="controls">
                    <input type="text" class="input-normal" id="title" name="title"/>
                </div>
            </div>
            <div class="control-group span7">
                <label class="control-label">类型:</label>
                <div class="controls">
                    <#assign map = {'index_top':'index_top','index_right_top':'index_right_top','index_right_bottom':'index_right_bottom','newslist_right_top':'newslist_right_top','newslist_right_bottom':'newslist_right_bottom','flashlist_right_top':'flashlist_right_top','flashlist_right_bottom':'flashlist_right_bottom'}>
                    <select id="code" name="code" class="input-normal">
                        <#list map?keys as key>
                            <option value="${key}"
                                    <#if e.code?? && e.code==key>selected="selected" </#if>>${map[key]}</option>
                        </#list>
                    </select>
                </div>
            </div>
            <div class="control-group span10">
                <div class="controls">
                    <label class="control-label">时间范围:</label>
                    <input name="startDate" class="input-small calendar" type="text" id="d4311"/>
                    <label>&nbsp;-&nbsp;</label>
                    <input name="endDate" class="input-small calendar" type="text" id="d4312"/>
                </div>
            </div>
        </li>
        <li>
            <div class="form-actions span12">
                <a class="button  button-primary">
                    查询
                </a>
                <a href="javascript:add()" class="button button-success">
                    <i class="icon-plus-sign icon-white"></i> 添加
                </a>
                <a class="button button-danger" onclick="return delFunction()">
                    删除
                </a>
            </div>
        </li>
    </ul>
</form>
<#----------------------------------------------查询表单end----------------------------------------------->
<#--表格数据-->
<div id="grid"></div>
<#----------------------------------------------新增表单begin----------------------------------------------->
<div id="content" style="display:none;">
    <form id="addForm" class="form-horizontal" action="${basepath}/manage/advert/insertJson" method="post">
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">标题：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="title" >
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">类型：</label>

                <div class="controls">
                    <#assign map = {'index_top':'index_top','index_right_top':'index_right_top','index_right_bottom':'index_right_bottom','newslist_right_top':'newslist_right_top','newslist_right_bottom':'newslist_right_bottom','flashlist_right_top':'flashlist_right_top','flashlist_right_bottom':'flashlist_right_bottom'}>
                    <select  name="code" class="input-normal">
                        <#list map?keys as key>
                            <option value="${key}" <#if e.code?? && e.code==key>selected="selected" </#if>>${map[key]}</option>
                        </#list>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">状态：</label>

                <div class="controls">
                    <select name="status" class="input-normal">
                        <option value="y">启用</option>
                        <option value="n">禁用</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">是否优先使用图集：</label>
                <div class="controls">
                    <select name="useImagesRandom" class="input-normal">
                        <option value="y">优先</option>
                        <option value="n">不优先</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <div class="controls">
                    <label class="control-label">时间范围:</label>
                    <input name="startDate" class="input-small calendar" type="text" id="d4311"/>
                    <label>&nbsp;-&nbsp;</label>
                    <input name="endDate" class="input-small calendar" type="text" id="d4312"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">内容：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="html" >
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------新增表单end-------------------------------------------------->
<#----------------------------------------------编辑表单start------------------------------------------------>
<div id="editContent" style="display:none;">
    <form id="editForm" class="form-horizontal" action="${basepath}/manage/advert/updateJson" method="post">
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">标题：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="title" >
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">类型：</label>

                <div class="controls">
                    <#assign map = {'index_top':'index_top','index_right_top':'index_right_top','index_right_bottom':'index_right_bottom','newslist_right_top':'newslist_right_top','newslist_right_bottom':'newslist_right_bottom','flashlist_right_top':'flashlist_right_top','flashlist_right_bottom':'flashlist_right_bottom'}>
                    <select  name="code" class="input-normal">
                        <#list map?keys as key>
                            <option value="${key}" <#if e.code?? && e.code==key>selected="selected" </#if>>${map[key]}</option>
                        </#list>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">状态：</label>

                <div class="controls">
                    <select name="status" class="input-normal">
                        <option value="y">启用</option>
                        <option value="n">禁用</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">是否优先使用图集：</label>
                <div class="controls">
                    <select name="useImagesRandom" class="input-normal">
                        <option value="y">优先</option>
                        <option value="n">不优先</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">内容：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="html" >
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------编辑表单end-------------------------------------------------->
<#--------------------------------------------表格数据渲染begin---------------------------------------------->
<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '广告标题', dataIndex: 'title', width: '12%'},
                {title: 'code', dataIndex: 'code', width: '12%'},
                {
                    title: '有效日期范围', dataIndex: '', width: '12%', renderer: function (data, obj, index) {
                    return obj.startdate + '~' + obj.enddate;
                }
                },
                {
                    title: '状态', dataIndex: 'status', width: '12%', renderer: function (data) {
                    if (data == "y") {
                        return '<img src="${basepath}/resource/images/action_check.gif">';
                    } else {
                        return '<img src="${basepath}/resource/images/action_delete.gif">';
                    }
                }
                },
                {
                    title: '图集优先', dataIndex: 'useImagesRandom', width: '12%', renderer: function (data) {
                    if (data == "y") {
                        return '<img src="${basepath}/resource/images/action_check.gif">';
                    } else {
                        return '<img src="${basepath}/resource/images/action_delete.gif">';
                    }
                }
                },
                {
                    title: '操作', dataIndex: 'id', width: '12%', renderer: function (value) {

                    <#if checkPrivilege("/manage/advert/edit")>
                        return '<a href="javascript:edit(' + value + ')">编辑</a>';
                    <#else>
                        return "";
                    </#if>


                }
                }
            ];
    var store = new Store({
                url : 'loadData',
                autoLoad:true, //自动加载数据
                params : { //配置初始请求的参数
                    length : '10',
                    status:$("#status").val()
                },
                pageSize:10,	// 配置分页数目
                root : 'list',
                totalProperty : 'total'
            }),
            grid = new Grid.Grid({
                render:'#grid',
                columns : columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar:{
                    pagingBar:true
                }
            });
    grid.render();

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();
    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /*----------------------------------------------表格数据渲染end----------------------------------------*/
    /*----------------------------------------------新增表单处理 begin------------------------------------*/
    var addForm = new BUI.Form.Form({
        srcNode: '#addForm',
        submitType : 'ajax',
        callback : function(data){
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addDialog.close();
        }
    }).render();

    var addDialog = new BUI.Overlay.Dialog({
        title: '新增广告',
        width: 500,
        height: 320,
        contentId: 'content',
        success: function () {
            addForm.ajaxSubmit();
        }
    });
    //添加按钮事件
    function add() {
        addDialog.show();
    }
    /*----------------------------------------------新增表单处理 end------------------------------------*/
    /*----------------------------------------------编辑表单处理start-----------------------------------*/
    var editForm = new BUI.Form.Form({
        srcNode: '#editForm',
        submitType : 'ajax',
        callback : function(data){
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            editDialog.close();
        }
    });
    editForm.render();

    var editDialog = new BUI.Overlay.Dialog({
        title: '编辑配送方式',
        width: 500,
        height: 320,
        contentId: 'editContent',
        success: function () {
            editForm.ajaxSubmit();
        }
    });
    //编辑按钮事件
    function edit(id) {
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"${basepath}/manage/advert/toEditJson",
            data:{id:id},
            success:function(data) {
                var form =$("#editForm")[0];
                BUI.FormHelper.setFields(form,data.data);
                editDialog.show();
            }
        });
    }
    /*----------------------------------------------编辑表单处理 end------------------------------------*/

    //删除选中的记录
    function delFunction() {
        var selections = grid.getSelection();
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids[i] = selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/manage/advert/deletesJson",
            dataType: "json",
            data: {
                ids: ids
            },
            success: function (data) {
                var obj = new Object();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });

    }
</script>
<#--<style type="text/css">-->
<#--.aCss {-->
<#--overflow: hidden;-->
<#--word-break: keep-all;-->
<#--white-space: nowrap;-->
<#--text-overflow: ellipsis;-->
<#--text-align: left;-->
<#--font-size: 12px;-->
<#--}-->
<#--</style>-->
<#--<form action="${basepath}/manage/advert" method="post" theme="simple">-->
<#--<table class="table table-bordered">-->
<#--<tr>-->
<#--<td>广告标题</td>-->
<#--<td><input type="text"  value="${e.title!""}" name="title" class="input-medium search-query" /></td>-->
<#--<td>类型</td>-->
<#--<td>-->
<#--<#assign map = {'index_top':'index_top','index_right_top':'index_right_top','index_right_bottom':'index_right_bottom','newslist_right_top':'newslist_right_top','newslist_right_bottom':'newslist_right_bottom','flashlist_right_top':'flashlist_right_top','flashlist_right_bottom':'flashlist_right_bottom'}>-->
<#--<select id="code" name="code" class="input-medium">-->
<#--<#list map?keys as key>-->
<#--<option value="${key}" <#if e.code?? && e.code==key>selected="selected" </#if>>${map[key]}</option>-->
<#--</#list>-->
<#--</select>-->
<#--</td>-->
<#--<!-- -->
<#--<td>时间范围</td>-->
<#--<td>-->
<#--<input id="d4311" class="Wdate search-query input-small" type="text" name="createtime"-->
<#--value="<s:property value="e.createtime" />"-->
<#--onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'d4312\')||\'2020-10-01\'}'})"/>-->
<#--~ -->
<#--<input id="d4312" class="Wdate search-query input-small" type="text" name="createtimeEnd"-->
<#--value="<s:property value="e.createtimeEnd" />"-->
<#--onFocus="WdatePicker({minDate:'#F{$dp.$D(\'d4311\')}',maxDate:'2020-10-01'})"/>-->
<#--</td>-->
<#--&ndash;&gt;-->
<#--</tr>-->
<#--<tr>-->
<#--<td colspan="16">-->
<#--<button method="selectList" class="btn btn-primary" onclick="selectList(this)">-->
<#--<i class="icon-search icon-white"></i> 查询-->
<#--</button>-->
<#---->
<#--<a href="toAdd" class="btn btn-success">-->
<#--<i class="icon-plus-sign icon-white"></i> 添加-->
<#--</a>-->
<#---->
<#--<button method="deletes" class="btn btn-danger" onclick="return submitIDs(this,'确定删除选择的记录?');">-->
<#--<i class="icon-remove-sign icon-white"></i> 删除-->
<#--</button>-->
<#---->
<#--<div style="float: right;vertical-align: middle;bottom: 0px;top: 10px;">-->
<#--<#include "/manage/system/pager.ftl">-->
<#--</div>-->
<#--</td>-->
<#--</tr>-->
<#--</table>-->

<#--<table class="table table-bordered table-hover">-->
<#--<tr class="success">-->
<#--<td width="20px"><input type="checkbox" id="firstCheckbox" /></td>-->
<#--<td>广告标题</td>-->
<#--<td width="180px">code</td>-->
<#--<td width="180px">有效日期范围</td>-->
<#--<td width="80px">状态</td>-->
<#--<td width="80px">图集优先</td>-->
<#--<td width="50px">操作</td>-->
<#--</tr>-->

<#--<#list pager.list as item>-->
<#--<tr>-->
<#--<td><input type="checkbox" name="ids"-->
<#--value="${item.id!""}" /></td>-->
<#--<td class="aCss">-->
<#--<a href="toEdit?id=${item.id}"-->
<#-->${item.title!""}</a>-->
<#--</td>-->
<#--<td>&nbsp;${item.code!""}</td>-->
<#--<td>&nbsp;${item.startdate!""} ~ ${item.enddate!""}</td>-->
<#--<td>&nbsp;-->
<#--<#if item.status??&&item.status=="y">-->
<#--<img alt="显示" src="${basepath}/resource/images/action_check.gif">-->
<#--<#else>-->
<#--<img alt="不显示" src="${basepath}/resource/images/action_delete.gif">-->
<#--</#if>-->
<#--</td>-->
<#--<td>&nbsp;-->
<#--<#if  item.useImagesRandom??&&item.useImagesRandom=="y">-->
<#--<img alt="显示" src="${basepath}/resource/images/action_check.gif">-->
<#--<#else>-->
<#--<img alt="不显示" src="${basepath}/resource/images/action_delete.gif">-->
<#--</#if>-->
<#--</td>-->
<#--<td ><a href="toEdit?id=${item.id}">编辑</a></td>-->
<#--</tr>-->
<#--</#list>-->

<#--<tr>-->
<#--<td colspan="7" style="text-align: center;font-size: 12px;"><#include "/manage/system/pager.ftl"></td>-->
<#--</tr>-->
<#--</table>-->
<#---->
<#--<div class="alert alert-info" style="text-align: left;font-size: 14px;margin: 2px 0px;">-->
<#--图标含义：<BR>-->
<#--<img alt="显示" src="${basepath}/resource/images/action_check.gif">：显示到门户上-->
<#--<img alt="不显示" src="${basepath}/resource/images/action_delete.gif">：不显示到门户上-->
<#--</div>-->

<#--</form>-->

</@page.pageBase>